#include <bits/stdc++.h>

#define eb emplace_back
#define ep emplace
#define fi first
#define se second
#define in read<int>()
#define lin read<ll>()
#define rep(i, x, y) for(int i = (x); i <= (y); i++)
#define per(i, x, y) for(int i = (x); i >= (y); i--)

using namespace std;

using ll = long long;
using db = double;
using pii = pair < int, int >;
using vec = vector < int >;
using veg = vector < pii >;

template < typename T > T read() {
	T x = 0; bool f = 0; char ch = getchar();
	while(!isdigit(ch)) f |= ch == '-', ch = getchar();
	while(isdigit(ch)) x = x * 10 + (ch ^ 48), ch = getchar();
	return f ? -x : x;
}

template < typename T > void chkmax(T &x, const T &y) { x = x > y ? x : y; }
template < typename T > void chkmin(T &x, const T &y) { x = x < y ? x : y; }

const int N = 300;
const int S = 1 << 16;
const int mod = 10007;

int n, m;
int f[2][S], U;
char a[N][N];

int main() {
#ifndef ONLINE_JUDGE
	freopen("1.in", "r", stdin);
#endif
	n = in, m = in; rep(i, 1, n) scanf("%s", a[i] + 1);
	if(n < m) {
		rep(i, 1, n) rep(j, 1, m) if(i < j) swap(a[i][j], a[j][i]);
		swap(n, m);
	}
	int o = 0; f[o][0] = 1; U = 1 << m; U--;
	rep(i, 1, n) {
		memset(f[o ^ 1], 0, sizeof f[o ^ 1]);
		int unstu = 0, tstu = 0; rep(j, 1, m) if(a[i][j] == '.') unstu |= 1 << j - 1; else tstu |= (a[i][j] - '0') << j - 1;
		rep(s, 0, U) if(f[o][s]) { 
			for(int v = U ^ s, t = v; ; t = (t - 1) & v) {
				if(t & (t << 1)) continue; if(t & (t >> 1)) continue;
				if((t - (t & unstu)) == tstu) (f[o ^ 1][t] += f[o][s]) %= mod;
				if(t == 0) break;
			}
		} o ^= 1;
	} int ans = 0; rep(s, 0, U) (ans += f[o][s]) %= mod; printf("%d\n", ans);
	return 0;
}
